package com.ym.b2b.commons.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;

import com.ym.b2b.commons.conf.AgentToken;
import com.ym.b2b.commons.conf.B2BConstants;
import com.ym.b2b.commons.conf.WebProviderTokenUser;
import com.ym.b2b.commons.conf.WebTokenUser;
import com.zc.commons.controller.ZcController;
import com.zc.security.acl.domain.Users;
import com.zc.security.acl.response.ResponseLoginResult;

public abstract class BaseController extends ZcController {

    protected WebTokenUser getWebTokenUser(HttpServletRequest req) {

        return (WebTokenUser) req.getSession().getAttribute(B2BConstants.WEB_USER_TOKEN);

    }

    protected WebProviderTokenUser getWebProviderTokenUser(HttpServletRequest req) {

        return (WebProviderTokenUser) req.getSession().getAttribute(B2BConstants.WEB_PROVIDER_TOKEN);

    }

    protected AgentToken getAgentToken(HttpServletRequest req) {

        return (AgentToken) req.getSession().getAttribute(B2BConstants.WEB_AGENT);

    }

    protected Users getManagerTokenUser(HttpServletRequest req) {
        ResponseLoginResult ret = (ResponseLoginResult) req.getSession().getAttribute("GRANT_INFO");
        return ret.getRESPONSE_DATA().getUSER_INFO();

    }

    protected void setErrorRet(ModelAndView m, Exception e) {
        m.addObject("msg", e.getMessage());
        m.setViewName(B2BConstants.WEB_ERROR);
    }

}
